package org.jw.wishlist.resolver;

import lombok.extern.slf4j.Slf4j;
import org.jw.wishlist.entity.source.ItemSource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

/**
 * @author Jiawei Zhao
 */
@Slf4j
public class XiaoHongShuItemSourceResolver extends ItemSourceSupports implements ItemSourceResolver {

  private static final String GET_FOR_LONG_URL = "https://api.dwzjh.com/api/reduction?url=%s";

  public XiaoHongShuItemSourceResolver(RestTemplate restTemplate) {
    super(restTemplate);
  }

  @Override
  public ItemSource resolve(String linkCode) {

    String url = extractUrl(linkCode);
    ResponseEntity<String> entity = restTemplate.getForEntity(String.format(GET_FOR_LONG_URL, url), String.class);
    String res = entity.getBody();
    log.debug("status: {}, headers: {}", entity.getStatusCode(), entity.getHeaders());

    return null;
  }

}
